
/**SIGCH*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include<signal.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<errno.h>

static void wait_child(int sig)
{
	printf("parent process reback child\n");
	while(waitpid(-1,NULL,WNOHANG)>0)
		continue;
}
int main(void)
{
	struct sigaction sig={0};
	sigemptyset(&sig.sa_mask);
	sig.sa_handler=wait_child;
	sig.sa_flags=0;
	if(-1==sigaction(SIGCHLD,&sig,NULL)){
		perror("sigaction error");
		exit(-1);
	}
	switch(fork()){
		case -1:
			perror("fork error");
			exit(-1);
		case 0:
			printf("child process<%d> created\n",getpid());
			sleep(1);
			printf("child process terminated\n");
			_exit(0);
		default:
			break;
	}
	while(1)
	{
		sleep(1);
	}
	sleep(3);
	return 0;
}
